package com.chanyachting.emall.domain;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.chanyachting.emall.dao.NewsactivityDAO;
import com.chanyachting.emall.domain.base.BaseNewsactivity;

/**
 * This is the object class that relates to the newsactivity table.
 * Any customizations belong here.
 */
public class Newsactivity extends BaseNewsactivity {

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Newsactivity () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Newsactivity (java.lang.Integer _id) {
		super(_id);
		
		Newsactivity na=(Newsactivity) new NewsactivityDAO().load(Newsactivity.class, _id);
		
		if(na!=null){
			
			try {
				BeanUtils.copyProperties(this, na);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}

	/**
	 * Constructor for required fields
	 */
	public Newsactivity (
		java.lang.Integer _id,
		java.lang.Integer _memberId,
		java.lang.String _status) {

		super (
			_id,
			_memberId,
			_status);
	}
/*[CONSTRUCTOR MARKER END]*/
	
	
	public static int countByMemberIdAndStatus(int memberId,String status){
		
		String args[]={String.valueOf(memberId),status};
		
		List list=new NewsactivityDAO().find("select count(id) as ct from Newsactivity where memberId=? and status=?",args);
		
		return Integer.parseInt(list.get(0).toString()) ;
		
	}
	
	
	public static int countByMemberIdAndRecommend(int memberId,int recommend){
		
		String args[]={String.valueOf(memberId),String.valueOf(recommend)};
		
		List list=new NewsactivityDAO().find("select count(id) as ct from Newsactivity where memberId=? and recommend=?",args);
		
		return Integer.parseInt(list.get(0).toString()) ;
		
	}
	
	
	public static List<Newsactivity> listByMemberIdAndRecommend(int memberId,int recommend){
		
		String args[]={String.valueOf(memberId),String.valueOf(recommend)};
		
		return new NewsactivityDAO().find("from Newsactivity where memberId=? and recommend=?",args);
	}
	
	
	public static List<Newsactivity> listByMemberIdAndRecommendWithPage(
			int memberId,int recommend,int firstIndex,int maxSize){
		
		String args[]={String.valueOf(memberId),String.valueOf(recommend)};
		
		if(maxSize==0) maxSize=5;
		
		return new NewsactivityDAO().find("from Newsactivity where memberId=? and recommend=?",args,firstIndex,maxSize);
	}
	
	
	
	
	public static List<Newsactivity> listByMemberIdAndStatus(int memberId,String status){
		
		String args[]={String.valueOf(memberId),status};
		
		return new NewsactivityDAO().find("from Newsactivity where memberId=? and status=?",args);
	}
	
	
	public static List<Newsactivity> listByMemberIdAndStatusWithPage(
			int memberId,String status,int firstIndex,int maxSize){
		
		String args[]={String.valueOf(memberId),status};
		
		if(maxSize==0) maxSize=5;
		
		return new NewsactivityDAO().find("from Newsactivity where memberId=? and status=?",args,firstIndex,maxSize);
	}
	
	
	public static List listByAudit(int audit){
		
		String args[]={String.valueOf(audit)};
		
		return new NewsactivityDAO().find("from Newsactivity where audit=?",args);
	}
	
	public static List listByRecommend(int recommend){
		
		String args[]={String.valueOf(recommend)};
		
		return new NewsactivityDAO().find("from Newsactivity where recommend=?",args);
	}
	
	
	public static List listByStatus(String status){
		
		String args[]={status};
		
		return new NewsactivityDAO().find("from Newsactivity where status=?",args);
	}
	
	
	public static List list(){
		
		return new NewsactivityDAO().find("from Newsactivity");
		
	}
	
	public boolean update(){
		
		new NewsactivityDAO().update(this);
		
		return true;
	}
	
	
}